package cn.hx.controller.system;

import cn.hx.entity.Item;
import cn.hx.entity.UserInfo;
import cn.hx.entity.UserReport;
import cn.hx.service.ItemService;
import cn.hx.service.UserReportService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * (UserReport)表控制层
 *
 * @author makejava
 * @since 2022-08-19 17:33:23
 */
@Controller

public class SystemUserReportController {

    @Resource
    private UserReportService userReportService;
    @Resource
    private ItemService itemService;


    /*@GetMapping("system/declare/declareList")
    public String declareList(ModelMap modelMap) {
        modelMap.addAttribute("declares", userReportService.queryAllByLimit(0, 1000));
        return "system/declare/declareList";
    }*/
    @GetMapping("system/declare/declareEdit")
    public String addList(UserReport userReport,ModelMap modelMap){
        modelMap.addAttribute("deptLists",itemService.queryAllByLimit(new Item(),0,1000));
            modelMap.addAttribute("addList",userReportService.queryAllByLimit(userReport,0,100));
        return "system/declare/declareEdit";
    }
    @PostMapping("system/declare/declareEdit")
    public String add(UserReport userReport){
        System.out.println(userReport);
        userReportService.insert(userReport);
        return "redirect:/system/declare/declareList";
    }
    @GetMapping("system/declare/declareEdit/{id}")
    public String updateList(@PathVariable Integer id, ModelMap modelMap){
        modelMap.addAttribute("deptLists",itemService.queryAllByLimit(new Item(),0,1000));
           modelMap.addAttribute("updateList",userReportService.queryById(id));
        return "system/declare/declareEdit";
    }
    @PostMapping("system/declare/declareEdit/{id}")
    public String update(UserReport userReport){

        System.out.println(userReport);
        userReport.setProcessingTime(new Date());
        userReportService.update(userReport);
        return "redirect:/system/declare/declareList";
    }

    @GetMapping("system/declare/declareList/{id}")
    public String delete(@PathVariable Integer id){
        userReportService.deleteById(id);
        return "redirect:/system/declare/declareList";
    }

    @GetMapping("system/declare/declareList")
    public String userLists(
            ModelMap modelMap,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "5") int size,
            UserReport userReport
            ) {
        /*modelMap.addAttribute("declares", userReportService.queryAllByLimit(0, 1000));*/
        modelMap.addAttribute("Page",userReportService.page(userReport,page, size));
        return "system/declare/declareList";
    }


}